package k2_oop.p9_collection.demo01;

import java.util.Optional;
import java.util.Random;
import java.util.stream.Stream;

public class UseOptional {

    public static void main(String[] args) {

        Stream<Integer> nums = Stream.of();

        Optional<Integer> optional = nums.max((n1, n2)->n1-n2);

        System.out.println(optional);

//        System.out.println(optional.get());

//        System.out.println(optional.orElse(-1));

//        Random random = new Random();
//        System.out.println(optional.orElseGet(() -> random.nextInt()));

//        System.out.println(optional.orElseThrow(()->new RuntimeException("test")));

        Optional<String> o1 = Optional.empty();
        System.out.println(o1);

        Optional<String> o2 = Optional.ofNullable(null);
        System.out.println(o2);

    }
}
